package com.opencloud.ywt.provider.controller;

import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.opencloud.common.model.PageParams;
import com.opencloud.common.model.ResultBody;
import com.opencloud.ywt.client.model.entity.*;
import com.opencloud.ywt.provider.service.BhyfAngleService;
import com.opencloud.ywt.provider.service.BhyfStudentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * 区角记录
 * @author yeyong
 */
@RestController
@Api(value = "区角记录", tags = "区角记录")
public class BhyfXhbAngleController {
    @Autowired
    private BhyfAngleService bhyfAngleService;
    @Autowired
    private BhyfStudentService bhyfStudentService;

    /**
     * 获取个人的区角统计记录
     * @param personid
     * @param angleid
     * @param startTime
     * @param endTime
     * @return
     */
    @ApiOperation(value = "获取个人的区角统计记录", notes = "获取个人的区角统计记录")
    @GetMapping("/angle/personlist")
    public ResultBody<List<BhyfXhbAnglePerson>> getPersonAngleList(
            @RequestParam(required = false     ) Integer classid,
            @RequestParam(required = false   ) Integer personid,
            @RequestParam(required = false   ) Integer angleid,
            @RequestParam(required = true   ) String startTime,
            @RequestParam(required = true   ) String endTime
    )
    {
        if(classid==null){classid=-1;}
        if(personid==null){personid=-1;}
        if(angleid==null){angleid=-1;}
        //return ResultBody.ok().data(bhyfAngleService.GetBhfyXhbAnglePersonListByService(classid,personid,angleid,startTime,endTime));
        return ResultBody.ok().data(bhyfAngleService.findXhbAnglePersonList(classid,personid,angleid,startTime,endTime));
    }

    /**
     * 获取个人的区角进出记录
     * @param personid
     * @param angleid
     * @param startTime
     * @param endTime
     * @return
     */
    @ApiOperation(value = "获取个人的区角进出记录", notes = "获取个人的区角进出记录")
    @GetMapping("/angle/recordlist")
    public ResultBody<List<BhyfXhbAngleRecord>> getPersonAngleRecordList(
            @RequestParam(required = false   ) Integer classid,
            @RequestParam(required = false   ) Integer personid,
            @RequestParam(required = false   ) Integer angleid,
            @RequestParam(required = true   ) String startTime,
            @RequestParam(required = true   ) String endTime
    )
    {
        if(classid==null){classid=-1;}
        if(personid==null){personid=-1;}
        if(angleid==null){angleid=-1;}
        //return ResultBody.ok().data(bhyfAngleService.findRealtimeXhbAngleRecordList(classid,personid,angleid,startTime,endTime));
        return ResultBody.ok().data(bhyfAngleService.findXhbAngleRecordList(classid,personid,angleid,startTime,endTime));
    }

    /**
     * 获取班级的区角统计记录
     * @param classid
     * @param angleid
     * @param startTime
     * @param endTime
     * @return
     */
    @ApiOperation(value = "获取班级的区角统计记录", notes = "获取班级的区角统计记录")
    @GetMapping("/angle/classlist")
    public ResultBody<List<BhyfXhbAngleClass>> getClassAngleRecordList(
            @RequestParam(required = true   ) Integer classid,
            @RequestParam(required = false   ) Integer angleid,
            @RequestParam(required = true   ) String startTime,
            @RequestParam(required = true   ) String endTime
    )
    {
        if(angleid==null){angleid=-1;}
        //return ResultBody.ok().data(bhyfAngleService.GetBhfyXhbAngleClassListByService(classid,angleid,startTime,endTime));
        return ResultBody.ok().data(bhyfAngleService.findXhbAngleClassList(classid,angleid,startTime,endTime));
    }

    /**
     * 获取个人的区角伙伴列表
     * @param personid
     * @param angleid
     * @param count
     * @param startTime
     * @param endTime
     * @return
     */
    @ApiOperation(value = "获取个人的区角伙伴列表", notes = "获取个人的区角伙伴列表")
    @GetMapping("/angle/intersection/personlist")
    public ResultBody<IPage<BhyfXhbAngleIntersection>> getPersonAngleIntersectionList(
            @RequestParam(required = true   ) Integer personid,
            @RequestParam(required = false   ) Integer angleid,
            @RequestParam(required = true   ) Integer count,
            @RequestParam(required = false   ) String startTime,
            @RequestParam(required = false   ) String endTime
    )
    {
        if(angleid==null){angleid=-1;}
        return ResultBody.ok().data(bhyfAngleService.findXhbAngleIntersectionList(personid,angleid,count,startTime,endTime));
    }


    /**
     * 获取班级的区角伙伴列表
     * @param classid
     * @param angleid
     * @param count
     * @param startTime
     * @param endTime
     * @return
     */
    @ApiOperation(value = "获取班级的区角伙伴列表", notes = "获取班级的区角伙伴列表")
    @GetMapping("/angle/intersection/classlist")
    public ResultBody<IPage<BhyfXhbAngleIntersection>> getClassAngleIntersectionList(
            @RequestParam(required = true   ) Integer classid,
            @RequestParam(required = false   ) Integer angleid,
            @RequestParam(required = true   ) Integer count,
            @RequestParam(required = false   ) String startTime,
            @RequestParam(required = false   ) String endTime
    )
    {
        if(angleid==null){angleid=-1;}
        return ResultBody.ok().data(bhyfAngleService.findXhbAngleIntersectionClassList(classid,angleid,count,startTime,endTime));
    }

    /**
     * 获取区角观察记录
     * @param ,map
     * @param startTime
     * @param endTime
     * @return
     */
    @ApiOperation(value = "获取区角观察记录", notes = "获取区角观察记录")
    @GetMapping("/angle/observrecordlist")
    public ResultBody<IPage<BhyfXhbAngleObservRecord>> getXhbAngleObservRecordList(
            @RequestParam(required = true) Map map,
            @RequestParam(required = false   ) String startTime,
            @RequestParam(required = false   ) String endTime
    )
    {
        return ResultBody.ok().data(bhyfAngleService.findXhbAngleObservRecordList(new PageParams(map),startTime,endTime));
    }

    /**
     * 获取区角观察记录详情
     * @param id
     * @return
     */
    @ApiOperation(value = "获取区角观察记录详情", notes = "获取区角观察记录详情")
    @GetMapping("/angle/observrecordinfo")
    public ResultBody<IPage<BhyfXhbAngleObservRecord>> getXhbAngleObservRecordInfo(
            @RequestParam(required = true) Integer id
    )
    {
        return ResultBody.ok().data(bhyfAngleService.findXhbAngleObservRecordById(id));
    }

    /**
     * 新增区角的观察记录
     * @return
     */
    @ApiOperation(value = "新增区角的观察记录", notes = "新增区角的观察记录")
    @PostMapping("/angle/addobservrecord")
    public ResultBody<BhyfXhbAngleObservRecord> addBhyfXhbAngleObservRecord
            (@RequestParam(name = "personid") Long personid,
             @RequestParam(name = "studentname") String studentname,
             @RequestParam(name = "teacherid") Long teacherid,
             @RequestParam(name = "teachername") String teachername,
             @RequestParam(name = "angleid") Integer angleid,
             @RequestParam(name = "angletype") Integer angletype,
             @RequestParam(name = "anglegoods") String anglegoods,
             @RequestParam(name = "anglename") String anglename,
             @RequestParam(name = "gid") Integer gid,
             @RequestParam(name = "classid") Integer classid,
             @RequestParam(name = "classname") String classname,
             @RequestParam(name = "gradenum") Integer gradenum,
             @RequestParam(name = "observname") String observname,
             @RequestParam(name = "observdate") String observdate,
             @RequestParam(name = "objects",required = false) String objects,
             @RequestParam(name = "alearn",required = false) Integer alearn,
             @RequestParam(name = "blearn",required = false) Integer blearn,
             @RequestParam(name = "clearn",required = false) Integer clearn,
             @RequestParam(name = "status",required = false) Integer status,
             @RequestParam(name = "pics",required = false) String pics,
             @RequestParam(name = "casedescribe",required = false) String casedescribe,
             @RequestParam(name = "caseanalysis",required = false) String caseanalysis,
             @RequestParam(name = "videos",required = false) String videos,
             @RequestParam(name = "guid",required = false) String guid,
             @RequestParam(name = "goodssupport",required = false) String goodssupport,
             @RequestParam(name = "envsupport",required = false) String envsupport,
             @RequestParam(name = "friendsupport",required = false) String friendsupport,
             @RequestParam(name = "teachersupport",required = false) String teachersupport,
             @RequestParam(name = "othersupport",required = false) String othersupport,
             @RequestParam(name = "recordresult",required = false) String recordresult,
             @RequestParam(name = "ruletypeid",required = false) Integer ruletypeid,
             @RequestParam(name = "ruletypename",required = false) String ruletypename,
             @RequestParam(name = "ruleobjects",required = false) String ruleobjects,
             @RequestParam(name = "learnobjects",required = false) String learnobjects,
             @RequestParam(name = "supportobjects",required = false) String supportobjects
            )
    {
        BhyfXhbAngleObservRecord watchRecord = new BhyfXhbAngleObservRecord();
        watchRecord.setPersonid(personid);
        watchRecord.setAlearn(alearn);
        watchRecord.setAnglegoods(anglegoods);
        watchRecord.setAngleid(angleid);
        watchRecord.setAnglename(anglename);
        watchRecord.setAngletype(angletype);
        watchRecord.setBlearn(blearn);
        watchRecord.setCaseanalysis(caseanalysis);
        watchRecord.setCasedescribe(casedescribe);
        watchRecord.setClassid(classid);
        watchRecord.setClassname(classname);
        watchRecord.setClearn(clearn);
        watchRecord.setGid(gid);
        watchRecord.setGradenum(gradenum);
        watchRecord.setGuid(guid);
        watchRecord.setObservdate(DateUtil.parseDate(observdate));
        watchRecord.setObservname(observname);
        watchRecord.setObservobject(objects);
        watchRecord.setPics(pics);
        watchRecord.setRecorduid(teacherid);
        watchRecord.setRecorduname(teachername);
        watchRecord.setStudentname(studentname);
        watchRecord.setVideos(videos);
        watchRecord.setCreatetime(new Date());
        watchRecord.setUpdatetime(new Date());
        watchRecord.setStatus(status);
        watchRecord.setEnvsupport(envsupport);
        watchRecord.setTeachersupport(teachersupport);
        watchRecord.setRuletypename(ruletypename);
        watchRecord.setRuletypeid(ruletypeid);
        watchRecord.setRuleobjects(ruleobjects);
        watchRecord.setRecordresult(recordresult);
        watchRecord.setOthersupport(othersupport);
        watchRecord.setLearnobjects(learnobjects);
        watchRecord.setGoodssupport(goodssupport);
        watchRecord.setFriendsupport(friendsupport);
        watchRecord.setSupportobjects(supportobjects);
        watchRecord = bhyfAngleService.addBhyfXhbAngleObservRecord(watchRecord);
        return ResultBody.ok().data(watchRecord);
    }

    /**
     * 编辑区角的观察记录
     * @param id
     * @param status
     * @param alearn
     * @param blearn
     * @param clearn
     * @param videos
     * @param pics
     * @param caseanalysis
     * @param casedescribe
     * @param guid
     * @return
     */
    @ApiOperation(value = "编辑区角的观察记录", notes = "编辑区角的观察记录")
    @PostMapping("/angle/updateobservrecord")
    public ResultBody updateBhyfXhbAngleObservRecord
            (
                    @RequestParam(name = "id") Integer id,
                    @RequestParam(name = "angletype",required = false) Integer angletype,
                    @RequestParam(name = "status",required = false) Integer status,
                    @RequestParam(name = "alearn",required = false) Integer alearn,
                    @RequestParam(name = "blearn",required = false) Integer blearn,
                    @RequestParam(name = "clearn",required = false) Integer clearn,
                    @RequestParam(name = "videos",required = false) String videos,
                    @RequestParam(name = "pics",required = false) String pics,
                    @RequestParam(name = "caseanalysis",required = false) String caseanalysis,
                    @RequestParam(name = "casedescribe",required = false) String casedescribe,
                    @RequestParam(name = "guid",required = false) String guid,
                    @RequestParam(name = "goodssupport",required = false) String goodssupport,
                    @RequestParam(name = "envsupport",required = false) String envsupport,
                    @RequestParam(name = "friendsupport",required = false) String friendsupport,
                    @RequestParam(name = "teachersupport",required = false) String teachersupport,
                    @RequestParam(name = "othersupport",required = false) String othersupport,
                    @RequestParam(name = "recordresult",required = false) String recordresult,
                    @RequestParam(name = "ruletypeid",required = false) Integer ruletypeid,
                    @RequestParam(name = "ruletypename",required = false) String ruletypename,
                    @RequestParam(name = "ruleobjects",required = false) String ruleobjects,
                    @RequestParam(name = "learnobjects",required = false) String learnobjects,
                    @RequestParam(name = "supportobjects",required = false) String supportobjects,
                    @RequestParam(name = "anglegoods",required = false) String anglegoods
            )
    {
        BhyfXhbAngleObservRecord watchRecord = bhyfAngleService.findRecordInfoById(id);
        if(watchRecord!=null) {
            if(status!=null){watchRecord.setStatus(status);}
            watchRecord.setAngletype(angletype);
            watchRecord.setAlearn(alearn);
            watchRecord.setBlearn(blearn);
            watchRecord.setClearn(clearn);
            if(videos!=null){watchRecord.setVideos(videos);}
            if(pics!=null){watchRecord.setPics(pics);}
            if(caseanalysis!=null){watchRecord.setCaseanalysis(caseanalysis);}
            if(casedescribe!=null){watchRecord.setCasedescribe(casedescribe);}
            if(guid!=null){watchRecord.setGuid(guid);}
            watchRecord.setEnvsupport(envsupport);
            watchRecord.setTeachersupport(teachersupport);
            watchRecord.setRuletypename(ruletypename);
            watchRecord.setRuletypeid(ruletypeid);
            watchRecord.setRuleobjects(ruleobjects);
            watchRecord.setRecordresult(recordresult);
            watchRecord.setOthersupport(othersupport);
            watchRecord.setLearnobjects(learnobjects);
            watchRecord.setGoodssupport(goodssupport);
            watchRecord.setFriendsupport(friendsupport);
            watchRecord.setSupportobjects(supportobjects);
            if(anglegoods!=null){watchRecord.setAnglegoods(anglegoods);}
            watchRecord.setUpdatetime(new Date());
            bhyfAngleService.updateBhyfXhbAngleObservRecord(watchRecord);
        }
        return ResultBody.ok();
    }


    /**
     * 学生维度统计结果
     * @param gid
     * @param classid
     * @param checkdate
     * @return
     */
    @ApiOperation(value = "学生维度统计结果", notes = "学生维度统计结果")
    @GetMapping("/angle/record/persontongji")
    public ResultBody<List<BhyfXhbAngleRecordTongJiResult>> getXhbAngleRecordPersonTongji(
            @RequestParam(required = true   ) Integer gid,
            @RequestParam(required = true   ) Integer classid,
            @RequestParam(required = true   ) String checkdate
    )
    {
        List<BhyfXhbAngleRecordTongJiResult> results = bhyfAngleService.getAngleRecordTongJi(gid,classid,checkdate);
        if(results!=null) {
            for (int i = 0; i < results.size(); i++) {
                BhyfXhbAngleRecordTongJiResult r = results.get(i);
                String angleName = bhyfAngleService.getAngleNames(gid,classid,r.getPersonid(),checkdate);
                r.setAnglenames(angleName);
            }
        }
        return ResultBody.ok().data(results);
    }

    /**
     * 区角维度统计结果
     * @param gid
     * @param classid
     * @param checkdate
     * @return
     */
    @ApiOperation(value = "区角维度统计结果", notes = "区角维度统计结果")
    @GetMapping("/angle/record/angletongji")
    public ResultBody<List<BhyfXhbAngleRecordTongJiPerson>> getXhbAngleRecordAngleTongji(
            @RequestParam(required = true   ) Integer gid,
            @RequestParam(required = true   ) Integer classid,
            @RequestParam(required = true   ) String checkdate
    )
    {
        List<BhyfXhbAngleRecordTongJiPerson> results = bhyfAngleService.getAngleRecordPersonTongJi(gid,classid,checkdate);
        return ResultBody.ok().data(results);
    }

    /**
     * 获取区角的材料列表
     * @param map
     * @return
     */
    @ApiOperation(value = "获取区角的材料列表", notes = "获取区角的材料列表")
    @GetMapping("/angle/goodslist")
    public ResultBody<IPage<BhyfXhbAngleGoods>> getXhbAngleGoodsList(
            @RequestParam(required = true) Map map
    )
    {
        IPage<BhyfXhbAngleGoods> results = bhyfAngleService.findBhyfXhbAngleGoodsListPage(new PageParams(map));
        return ResultBody.ok().data(results);
    }


    /**
     *"获取园所的材料列表"
     * @param map
     * @return
     */
    @ApiOperation(value = "获取园所的材料列表", notes = "获取园所的材料列表")
    @GetMapping("/angle/allgoodslist")
    public ResultBody<IPage<BhyfXhbGoods>> getXhbGoodsList(
            @RequestParam(required = true) Map map
    )
    {
        IPage<BhyfXhbGoods> results = bhyfAngleService.findBhyfXhbGoodsListPage(new PageParams(map));
        return ResultBody.ok().data(results);
    }

    /**
     * 新增园所材料
     * @param goodsname
     * @param goodstype
     * @param goodslogo
     * @param gid
     * @param classid
     * @return
     */
    @ApiOperation(value = "新增园所材料", notes = "新增园所材料")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "goodsname", value = "物料名称", required = false, paramType = "form"),
            @ApiImplicitParam(name = "goodstype", value = "物料类型", required = false, paramType = "form"),
            @ApiImplicitParam(name = "goodslogo", value = "物料图片", required = false, paramType = "form"),
            @ApiImplicitParam(name = "gid", value = "园ID", required = false, paramType = "form"),
            @ApiImplicitParam(name = "classid", value = "班级ID", required = false, paramType = "form")
    })
    @PostMapping("/angle/addgoods")
    public ResultBody<BhyfXhbGoods> addBhyfXhbGoods
            (@RequestParam(name = "goodsname") String goodsname,
             @RequestParam(name = "goodstype") Integer goodstype,
             @RequestParam(name = "goodslogo") String goodslogo,
             @RequestParam(name = "gid") Integer gid,
             @RequestParam(name = "classid") Integer classid
            )
    {
        BhyfXhbGoods watchRecord = new BhyfXhbGoods();
        watchRecord.setClassid(classid);
        watchRecord.setGid(gid);
        watchRecord.setGoodslogo(goodslogo);
        watchRecord.setGoodsname(goodsname);
        watchRecord.setGoodstype(goodstype);
        watchRecord.setCreatetime(new Date());
        watchRecord = bhyfAngleService.addBhyfXhbGoods(watchRecord);
        return ResultBody.ok().data(watchRecord);
    }

    /**
     * 编辑园所材料
     * @param goodsname
     * @param goodstype
     * @param goodslogo
     * @return
     */
    @ApiOperation(value = "编辑园所材料", notes = "编辑园所材料")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "id", required = true, paramType = "form"),
            @ApiImplicitParam(name = "goodsname", value = "物料名称", required = false, paramType = "form"),
            @ApiImplicitParam(name = "goodstype", value = "物料类型", required = false, paramType = "form"),
            @ApiImplicitParam(name = "goodslogo", value = "物料图片", required = false, paramType = "form")
    })
    @PostMapping("/angle/updategoods")
    public ResultBody<Boolean> updateBhyfXhbGoods
    (
             @RequestParam(name = "id") Integer id,
             @RequestParam(name = "goodsname") String goodsname,
             @RequestParam(name = "goodstype") Integer goodstype,
             @RequestParam(name = "goodslogo") String goodslogo
    )
    {
        BhyfXhbGoods watchRecord = bhyfAngleService.findBhyfXhbGoodsById(id);
        if(watchRecord!=null) {
            watchRecord.setGoodslogo(goodslogo);
            watchRecord.setGoodstype(goodstype);
            watchRecord.setGoodsname(goodsname);
            bhyfAngleService.updateBhyfXhbGoods(watchRecord);
        }
        return ResultBody.ok().data(true);
    }

    /**
     * 删除园所材料
     * @param id
     * @return
     */
    @ApiOperation(value = "删除园所材料", notes = "删除园所材料")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "id", required = true, paramType = "form")
    })
    @PostMapping("/angle/deletegoods")
    public ResultBody<Boolean> deleteBhyfXhbGoods
            (
                    @RequestParam(name = "id") Integer id
            )
    {
        BhyfXhbGoods watchRecord = bhyfAngleService.findBhyfXhbGoodsById(id);
        if(watchRecord!=null) {
            bhyfAngleService.deleteBhyfXhbGoods(id);
        }
        return ResultBody.ok().data(true);
    }

    /**
     * 分配材料到区角(默认上架)
     * @param goodsid
     * @param angleid
     * @param gid
     * @param classid
     * @return
     */
    @ApiOperation(value = "分配材料到区角", notes = "分配材料到区角")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "goodsid", value = "物料ID", required = true, paramType = "form"),
            @ApiImplicitParam(name = "angleid", value = "区角ID", required = true, paramType = "form"),
            @ApiImplicitParam(name = "mac", value = "机器编号", required = true, paramType = "form"),
            @ApiImplicitParam(name = "goodsno", value = "框编号", required = true, paramType = "form"),
            @ApiImplicitParam(name = "gid", value = "园ID", required = true, paramType = "form"),
            @ApiImplicitParam(name = "classid", value = "班级ID", required = true, paramType = "form")
    })
    @PostMapping("/angle/addanglegoods")
    public ResultBody<BhyfXhbAngleGoods> addBhyfXhbAngleGoods
            (@RequestParam(name = "goodsid") Integer goodsid,
             @RequestParam(name = "angleid") Integer angleid,
             @RequestParam(name = "mac") String mac,
             @RequestParam(name = "goodsno") String goodsno,
             @RequestParam(name = "gid") Integer gid,
             @RequestParam(name = "classid") Integer classid
            )
    {
        //新增区角的材料分配
        BhyfXhbAngleGoods watchRecord = new BhyfXhbAngleGoods();
        watchRecord.setClassid(classid);
        watchRecord.setGid(gid);
        watchRecord.setMac(mac);
        watchRecord.setGoodsno(goodsno);
        BhyfBflAngle angle = bhyfStudentService.getBhyfBflAngleById(angleid);
        if(angle!=null) {
            watchRecord.setAngleid(angle.getId());
            watchRecord.setAnglename(angle.getAnglename());
            watchRecord.setAngletype(angle.getAngletype());
        }
        BhyfXhbGoods goods = bhyfAngleService.findBhyfXhbGoodsById(goodsid);
        if(goods!=null) {
            watchRecord.setGoodslogo(goods.getGoodslogo());
            watchRecord.setGoodsname(goods.getGoodsname());
            watchRecord.setGoodstype(goods.getGoodstype());
            watchRecord.setGoodsid(goods.getId());
        }
        watchRecord.setStatus(1);
        watchRecord.setCreatetime(new Date());
        watchRecord.setUpdatetime(new Date());
        //先判断是否存在
        List<BhyfXhbAngleGoods> oldGoods = bhyfAngleService.IsExistAngleGoods(angle.getId(),classid,goodsno,mac);
        if(oldGoods!=null && oldGoods.size()>0) {
            return ResultBody.failed().data(watchRecord);
        }else{
            watchRecord = bhyfAngleService.addBhyfXhbAngleGoods(watchRecord);
            //新增上下架记录
            BhyfXhbAngleGoodsRecord record = new BhyfXhbAngleGoodsRecord();
            if(watchRecord!=null) {
                record.setAnglegoodsid(watchRecord.getId());
                record.setStatus(1);
                record.setCreatetime(new Date());
                record.setUptime(new Date());
                record = bhyfAngleService.addBhyfXhbAngleGoodsRecord(record);
            }
            return ResultBody.ok().data(watchRecord);
        }

    }

    /**
     * 上/下架区角材料
     * @param id
     * @param status
     * @return
     */
    @ApiOperation(value = "上/下架区角材料", notes = "上/下架区角材料")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "id", required = true, paramType = "form"),
            @ApiImplicitParam(name = "status", value = "status", required = true, paramType = "form")
    })
    @PostMapping("/angle/updowngoods")
    public ResultBody<Boolean> updownBhyfXhbAngleGoods
            (
                    @RequestParam(name = "id") Integer id,
                    @RequestParam(name = "status") Integer status
            )
    {
        BhyfXhbAngleGoods watchRecord = bhyfAngleService.findBhyfXhbAngleGoodsById(id);
        if(watchRecord!=null) {
            //更新当前状态
            watchRecord.setStatus(status);
            watchRecord.setUpdatetime(new Date());
            if(status==0) {
                watchRecord.setDowntime(new Date());
            }
            bhyfAngleService.updateBhyfXhbAngleGoods(watchRecord);
            //添加上下架记录
            BhyfXhbAngleGoodsRecord record = new BhyfXhbAngleGoodsRecord();
            record.setAnglegoodsid(watchRecord.getId());
            record.setStatus(status);
            record.setCreatetime(new Date());
            if(status==1) {
                record.setUptime(new Date());
            }else{
                record.setDowntime(new Date());
            }
            bhyfAngleService.addBhyfXhbAngleGoodsRecord(record);
        }
        return ResultBody.ok().data(true);
    }

    /**
     * 获取区角的机器列表
     * @param gid
     * @param classid
     * @param angleid
     * @return
     */
    @ApiOperation(value = "获取区角的机器列表", notes = "获取区角的机器列表")
    @GetMapping("/angle/machine/list")
    public ResultBody<List<BhyfXhbAngleMachine>> getXhbAngleMachineList(
            @RequestParam(required = true   ) Integer gid,
            @RequestParam(required = false   ) Integer classid,
            @RequestParam(required = false   ) Integer angleid
    )
    {
        if(angleid==null){angleid=-1;}
        if(classid==null){classid=-1;}
        List<BhyfXhbAngleMachine> results = bhyfAngleService.getAngleMachineList(gid,classid,angleid);
        return ResultBody.ok().data(results);
    }

    /**
     * 获取材料的使用记录
     * @param gid
     * @param classid
     * @param angleid
     * @param personid
     * @param startTime
     * @param endTime
     * @return
     */
    @ApiOperation(value = "获取材料的使用记录", notes = "获取材料的使用记录")
    @GetMapping("/angle/goodsorder/list")
    public ResultBody<IPage<BhyfXhbAngleGoodsOrder>> getClassAngleIntersectionList(
            @RequestParam(required = true   ) Integer gid,
            @RequestParam(required = false   ) Integer classid,
            @RequestParam(required = false   ) Integer angleid,
            @RequestParam(required = false   ) Integer personid,
            @RequestParam(required = false   ) String startTime,
            @RequestParam(required = false   ) String endTime
    )
    {
        if(classid==null){classid=-1;}
        if(angleid==null){angleid=-1;}
        if(personid==null){personid=-1;}
        return ResultBody.ok().data(bhyfAngleService.getXhbAngleGoodsOrderList(gid,classid,angleid,personid,startTime,endTime));
    }

    /**
     * 获取班级学生区角的时长次数统计结果
     * @param gid
     * @param classid
     * @param startTime
     * @param endTime
     * @return
     */
    @ApiOperation(value = "获取班级学生区角的时长次数统计结果", notes = "获取班级学生区角的时长次数统计结果")
    @GetMapping("/angle/person/tongji")
    public ResultBody<List<BhyfXhbAnglePersonCount>> getAnglePersonCountAndSecondsTongji(
            @RequestParam(required = true   ) Integer gid,
            @RequestParam(required = true   ) Integer classid,
            @RequestParam(required = true   ) String startTime,
            @RequestParam(required = true   ) String endTime
    )
    {
        //return ResultBody.ok().data(bhyfAngleService.GetAnglePersonTongjiByService(gid,classid,startTime,endTime));
        return ResultBody.ok().data(bhyfAngleService.getAnglePersonCountAndSecondsTongji(gid,classid,startTime,endTime));
    }

    /**
     * 编辑区角材料
     * @param id
     * @param goodsfrom
     * @param goodsobject
     * @param goodsplace
     * @return
     */
    @ApiOperation(value = "编辑区角材料", notes = "编辑区角材料")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "id", required = true, paramType = "form"),
            @ApiImplicitParam(name = "goodsfrom", value = "物料来源", required = false, paramType = "form"),
            @ApiImplicitParam(name = "goodsobject", value = "建设目标", required = false, paramType = "form"),
            @ApiImplicitParam(name = "goodsplace", value = "使用场景", required = false, paramType = "form")
    })
    @PostMapping("/angle/updateanglegoods")
    public ResultBody<Boolean> updateBhyfXhbAngleGoods
            (
                    @RequestParam(name = "id") Integer id,
                    @RequestParam(name = "goodsfrom") String goodsfrom,
                    @RequestParam(name = "goodsobject") String goodsobject,
                    @RequestParam(name = "goodsplace") String goodsplace
            )
    {
        BhyfXhbAngleGoods watchRecord = bhyfAngleService.findBhyfXhbAngleGoodsById(id);
        if(watchRecord!=null) {
            watchRecord.setGoodsfrom(goodsfrom);
            watchRecord.setGoodsobject(goodsobject);
            watchRecord.setGoodsplace(goodsplace);
            bhyfAngleService.updateBhyfXhbAngleGoods(watchRecord);
        }
        return ResultBody.ok().data(true);
    }

    /**
     * 获取区角的材料的统计结果
     * @param gid
     * @param classid
     * @param angleid
     * @return
     */
    @ApiOperation(value = "获取区角的材料的统计结果", notes = "获取区角的材料的统计结果")
    @GetMapping("/angle/goodsuseresult")
    public ResultBody<List<BhyfXhbAngleGoods>> getXhbAngleGoodsListUseResult(
            @RequestParam(required = true) Integer gid,
            @RequestParam(required = true) Integer classid,
            @RequestParam(required = true) Integer angleid
    )
    {
        List<BhyfXhbAngleGoodsResult> results = new ArrayList<>();
        results = bhyfAngleService.getBhyfXhbAngleGoodsResultList(gid,classid,angleid);
        return ResultBody.ok().data(results);
    }

    /**
     * 新：获取区角的进出天数的结果
     * @param gid
     * @param classid
     * @param startdate
     * @param enddate
     * @return
     */
    @ApiOperation(value = "新：获取区角的进出天数的结果", notes = "新：获取区角的进出天数的结果")
    @GetMapping("/angle/playresult")
    public ResultBody<List<BhyfXhbAnglePlayResult>> getAngleRecordPlayResult(
            @RequestParam(required = true) Integer gid,
            @RequestParam(required = true) Integer classid,
            @RequestParam(required = true) String startdate,
            @RequestParam(required = true) String enddate
    )
    {
        List<BhyfXhbAnglePlayResult> results = new ArrayList<>();
        results = bhyfAngleService.getAngleRecordPlayResult(gid,classid,startdate,enddate);
        return ResultBody.ok().data(results);
    }

    /**
     * 新：获取区角的材料的使用结果
     * @param gid
     * @param classid
     * @param startdate
     * @param enddate
     * @return
     */
    @ApiOperation(value = "新：获取区角的材料的使用结果", notes = "新：获取区角的材料的使用结果")
    @GetMapping("/angle/goodsplayresult")
    public ResultBody<List<BhyfXhbAnglePlayGoodsResult>> getAngleGoodsPlayResult(
            @RequestParam(required = true) Integer gid,
            @RequestParam(required = true) Integer classid,
            @RequestParam(required = true) String startdate,
            @RequestParam(required = true) String enddate
    )
    {
        List<BhyfXhbAnglePlayGoodsResult> results = new ArrayList<>();
        results = bhyfAngleService.getAngleGoodsPlayResult(gid,classid,startdate,enddate);
        return ResultBody.ok().data(results);
    }

    /**
     * 实时:区角维度统计结果
     * @param gid
     * @param classid
     * @param checkdate
     * @return
     */
    @ApiOperation(value = "实时:区角维度统计结果", notes = "实时:区角维度统计结果")
    @GetMapping("/angle/record/realtime_angletongji")
    public ResultBody<List<BhyfXhbAngleRecordTongJiPerson>> getXhbRealtimeAngleRecordAngleTongji(
            @RequestParam(required = true   ) Integer gid,
            @RequestParam(required = true   ) Integer classid,
            @RequestParam(required = true   ) String checkdate
    )
    {
        List<BhyfXhbAngleRecordTongJiPerson> results = bhyfAngleService.getRealtimeAngleRecordPersonTongJi(gid,classid,checkdate);
        return ResultBody.ok().data(results);
    }


    /**
     * 实时:获取个人的区角进出记录
     * @param classid
     * @param personid
     * @param angleid
     * @param startTime
     * @param endTime
     * @return
     */
    @ApiOperation(value = "实时:获取个人的区角进出记录", notes = "实时:获取个人的区角进出记录")
    @GetMapping("/angle/realtime_recordlist")
    public ResultBody<List<BhyfXhbAngleRecord>> getRealtimePersonAngleRecordList(
            @RequestParam(required = false   ) Integer classid,
            @RequestParam(required = false   ) Integer personid,
            @RequestParam(required = false   ) Integer angleid,
            @RequestParam(required = false   ) String startTime,
            @RequestParam(required = false   ) String endTime
    )
    {
        if(classid==null){classid=-1;}
        if(personid==null){personid=-1;}
        if(angleid==null){angleid=-1;}
        return ResultBody.ok().data(bhyfAngleService.findRealtimeXhbAngleRecordList(classid,personid,angleid,startTime,endTime));
    }
}
